﻿//********************************************************************************//
//创建日期：<创建日期，2016-09-02>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：深井水价信息
//********************************************************************************//
using BLL;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.JiChuXX
{
    public partial class ShenJingSJXX : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量
        /// <summary>
        /// 取水用途
        /// </summary>
        QS_JX_SHUIZIYSJXX _QS_JX_SHUIZIYSJXX = new QS_JX_SHUIZIYSJXX();

        /// <summary>
        /// 取水用途bll
        /// </summary>
        QS_JX_SHUIZIYSJXXBLL _QS_JX_SHUIZIYSJXXBLL = new QS_JX_SHUIZIYSJXXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
                LoadData();
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        //protected override void Render(HtmlTextWriter sender)
        //{
        //    DataTable dt = _YS_JX_HANGYELXBLL.SelectYS_JX_HANGYELXesDynamic("1=0", "", null);
        //    base.Render(sender);
        //}

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                DataTable dtxx = _QS_JX_SHUIZIYSJXXBLL.SelectQS_JX_SHUIZIYSJXXesDynamic(string.Format("i_jlzt=0 and id={0}", id), null);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(dtxx.Rows[0]["S_SHUIJIABH"], dtxx.Rows[0]["N_SHUIJIA"], dtxx.Rows[0]["D_KAISHIRQ"], dtxx.Rows[0]["S_PIWENH"], dtxx.Rows[0]["S_MIAOSHU"]);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del")
            {
                this._QS_JX_SHUIZIYSJXX = _QS_JX_SHUIZIYSJXXBLL.SelectQS_JX_SHUIZIYSJXX(id);

                //设置逻辑删除
                this._QS_JX_SHUIZIYSJXX.I_JLZT = -1;
                //执行操作
                _SYS_LOGBLL.Log<QS_JX_SHUIZIYSJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "行业类型", OperateState.Delete, _QS_JX_SHUIZIYSJXX, null);
                if (_QS_JX_SHUIZIYSJXXBLL.InsertOrUpdate(_QS_JX_SHUIZIYSJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;

                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;

                //添加
                if (id == -1)
                {
                    this._QS_JX_SHUIZIYSJXX.ID = 0;
                    this._QS_JX_SHUIZIYSJXX.I_JLZT = 0;
                    _QS_JX_SHUIZIYSJXX.I_WTYPE = 1;
                    operateState = OperateState.Add;
                    if (_QS_JX_SHUIZIYSJXXBLL.SelectQS_JX_SHUIZIYSJXXesDynamic(string.Format("I_JLZT=0 and  S_SHUIJIABH='{0}' AND I_WTYPE=1", this.txtBianHao.Text), null).Rows.Count > 0)
                    {
                        cr.IsSuccess = false;
                        cr.IsAlertMsg = true;
                        cr.Msg = "您所输入深井水价编号系统中已经存在使用,请重新输入。";
                        e.Result = cr.ToString();
                        return;
                    }
                }
                //修改
                else
                {
                    //修改操作
                    this._QS_JX_SHUIZIYSJXX = this._QS_JX_SHUIZIYSJXXBLL.SelectQS_JX_SHUIZIYSJXX(id);
                    operateState = OperateState.Modify;
                }

                //判断编号是否存在
                

                _QS_JX_SHUIZIYSJXX.S_SHUIJIABH = txtBianHao.Text;
                _QS_JX_SHUIZIYSJXX.N_SHUIJIA = Convert.ToDouble(txtShuiJia.Text);
                _QS_JX_SHUIZIYSJXX.D_KAISHIRQ = Convert.ToDateTime(deKaiShiRQ.Text);
                _QS_JX_SHUIZIYSJXX.S_PIWENH = txtPiWenH.Text;
                _QS_JX_SHUIZIYSJXX.S_MIAOSHU = txtMiaoShu.Text;
                //设置操作信息
                _QS_JX_SHUIZIYSJXX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                _QS_JX_SHUIZIYSJXX.D_CAOZUORQ = DateTime.Now;
                _SYS_LOGBLL.Log<QS_JX_SHUIZIYSJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "深井水价信息", operateState, _QS_JX_SHUIZIYSJXX, null);
                if (_QS_JX_SHUIZIYSJXXBLL.InsertOrUpdate(_QS_JX_SHUIZIYSJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity = _QS_JX_SHUIZIYSJXX.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {

        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            this.dtSource = _QS_JX_SHUIZIYSJXXBLL.SelectQS_JX_SHUIZIYSJXXesDynamic("i_jlzt=0 AND I_WTYPE=1", "n_shuijia");
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData();
        }

        #endregion        
    }
}